var text_box_content = document.querySelector(".text_box_content");
var messages = document.querySelector(".messages")
var reply = document.querySelector(".chat_header_reply");
var throttle_valve = 1;
var send_button = document.querySelector(".send_button");
function showtime() {
    var nowdate = new Date(),
        h = nowdate.getHours(),
        m = nowdate.getMinutes(),
        h = checkTime(h),
        m = checkTime(m);
    if (h > 12) {
        return "Pm " + h + ":" + m;
    } else {
        return "Am " + h + ":" + m;
    }

}
var checkTime = function (i) {
    if (i < 10) {
        i = "0" + i;
    }
    return i;
}
window.addEventListener("load", function () {
    messages.scrollTop = (0, messages.scrollHeight);
})
send_button.addEventListener("click", function () {
    let box_content = text_box_content.value;
    if (box_content != null && box_content != "" && box_content != " " && box_content != "  ") {
        let div = document.createElement('div');
        if (box_content.indexOf('https') != -1 || box_content.indexOf('HTTPS') != -1 || box_content.indexOf('http') != -1 || box_content.indexOf('HTTP') != -1) {
            div.innerHTML = "<div class='messages_content' style='color:#9a15ff;'>" + box_content + "</div>"
                + "<div class='messages_action'>" + showtime() + "</div>";
        } else if (box_content.indexOf('想你') != -1) {
            div.innerHTML = "<div class='messages_content' style='color:#ff21b0;'>" + box_content + "</div>"
                + "<div class='messages_action'>" + showtime() + "</div>";
        } else if (box_content.indexOf('加油') != -1) {
            div.innerHTML = "<div class='messages_content' style='color:#1309ff;'>" + box_content + "</div>"
                + "<div class='messages_action'>" + showtime() + "</div>";
        } else {
            div.innerHTML = "<div class='messages_content'>" + box_content + "</div>"
                + "<div class='messages_action'>" + showtime() + "</div>";
        }
        div.className = "outgoing";
        let ci = messages.length;
        messages.insertBefore(div, messages.children[ci - 1]);
        messages.scrollTop = (0, messages.scrollHeight);
        text_box_content.value = "";
    }
    if (box_content.indexOf('想你') != -1) {
        if (throttle_valve == 1) {
            throttle_valve = 0;
            iwan();
        }
    } else if (box_content == "账号" || box_content == "zhanghao" || box_content == "密码" || box_content == "mima") {
        if (throttle_valve == 1) {
            throttle_valve = 0;
            password();
        }
    } else if (box_content == "网址") {
        if (throttle_valve == 1) {
            throttle_valve = 0;
            htmls();
        }
    } else if (box_content == "加油" || box_content == "一起努力" || box_content == "名言" || box_content == "文案") {
        if (throttle_valve == 1) {
            throttle_valve = 0;
            good();
        }
    } else if (box_content == "关键字") {
        if (throttle_valve == 1) {
            throttle_valve = 0;
            imp();
        }
    } else if (box_content == "123456") {
        if (throttle_valve == 1) {
            throttle_valve = 0;
            imps();
        }
    } else {
        if (throttle_valve == 1) {
            throttle_valve = 0;
            kan();
        }
    }
})

function iwan() {
    setTimeout(function () {
        reply.style.display = "block";
    }, 2000);
    setTimeout(function () {
        reply.style.display = "none";
        let div = document.createElement('div');
        div.innerHTML = "<div class='messages_content'>其实我也想你</div>"
            + "<div class='messages_action'>" + showtime() + "</div>";
        div.className = "messages_item";
        let ci = messages.length;
        messages.insertBefore(div, messages.children[ci - 1]);
        messages.scrollTop = (0, messages.scrollHeight);
        throttle_valve = 1;
    }, 8000)
}
function kan() {
    setTimeout(function () {
        reply.style.display = "block";
    }, 2000);
    setTimeout(function () {
        reply.style.display = "none";
        let div = document.createElement('div');
        div.innerHTML = "<div class='messages_content'>你有什么难过的事，都可以悄悄地跟我说哦，我保证不会泄露，用我明天的早餐发斯！</div>"
            + "<div class='messages_action'>" + showtime() + "</div>";
        div.className = "messages_item";
        let ci = messages.length;
        messages.insertBefore(div, messages.children[ci - 1]);
        messages.scrollTop = (0, messages.scrollHeight);
    }, 8000)
    setTimeout(function () {
        // reply.style.display = "none";
        let div = document.createElement('div');
        div.innerHTML = "<div class='messages_content'>我想“关键字”会对你很有帮助</div>"
            + "<div class='messages_action'>" + showtime() + "</div>";
        div.className = "messages_item";
        let ci = messages.length;
        messages.insertBefore(div, messages.children[ci - 1]);
        messages.scrollTop = (0, messages.scrollHeight);
        throttle_valve = 1;
    }, 12000)
}
function password() {
    setTimeout(function () {
        reply.style.display = "block";
    }, 1000);
    setTimeout(function () {
        reply.style.display = "none";
        let div = document.createElement('div');
        div.innerHTML = "<div class='messages_content'>账号：sfsdfsf<br>密码：12368</div>"
            + "<div class='messages_action'>" + showtime() + "</div>";
        div.className = "messages_item";
        let ci = messages.length;
        messages.insertBefore(div, messages.children[ci - 1]);
        messages.scrollTop = (0, messages.scrollHeight);
        throttle_valve = 1;
    }, 3000)
}
function imp() {
    setTimeout(function () {
        reply.style.display = "block";
    }, 1000);
    setTimeout(function () {
        reply.style.display = "none";
        let div = document.createElement('div');
        div.innerHTML = "<div class='messages_content'>请输入密码后使用VIP特权<br>密码：******</div>"
            + "<div class='messages_action'>" + showtime() + "</div>";
        div.className = "messages_item";
        let ci = messages.length;
        messages.insertBefore(div, messages.children[ci - 1]);
        messages.scrollTop = (0, messages.scrollHeight);
        throttle_valve = 1;
    }, 3000)
}
function imps() {
    setTimeout(function () {
        reply.style.display = "block";
    }, 1000);
    setTimeout(function () {
        reply.style.display = "none";
        let div = document.createElement('div');
        div.innerHTML = "<div class='messages_content'>学习通<br>账号：<i>15039711738</i><br>密码：<i>20020604XzW@</i></div>"
            + "<div class='messages_action'>" + showtime() + "</div>";
        div.className = "messages_item";
        let ci = messages.length;
        messages.insertBefore(div, messages.children[ci - 1]);
        messages.scrollTop = (0, messages.scrollHeight);
        throttle_valve = 1;
    }, 3000)
}
function htmls() {
    setTimeout(function () {
        reply.style.display = "block";
    }, 1000);
    setTimeout(function () {
        reply.style.display = "none";
        let div = document.createElement('div');
        div.innerHTML = "<div class='messages_content'><a href='https:www.baidu.com'>百度：<i>https:www.baidu.com</i></a><br><a href='https://www.runoob.com'>菜鸟：<i>https://www.runoob.com</i></a>"
            + "<div class='messages_action'>" + showtime() + "</div>";
        div.className = "messages_item";
        let ci = messages.length;
        messages.insertBefore(div, messages.children[ci - 1]);
        messages.scrollTop = (0, messages.scrollHeight);
        throttle_valve = 1;
    }, 3000)
}
function getRandom(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}
let newDay = ['新的开始，新的朝阳，美好的生活即将起航;迎着阳光，闻着花香，美妙的心情直往前方。上班开始了，工作启程了，加油，美好的生活等着你去开创。', '新的开始，新的朝阳，美好的生活即将起航;迎着阳光，闻着花香，美妙的心情直往前方。上班开始了，工作启程了，加油，美好的生活等着你去开创。', '所有回不去的良辰美景，都是举世无双的好时光，余生愿你常欢笑，别流泪，也别想他。晚安!', '所有回不去的良辰美景，都是举世无双的好时光，余生愿你常欢笑，别流泪，也别想他。晚安!', '余生，认真去生活，对自己好点，这世上没人能够保证你将来，除了你自己！', '白天就好好读书，书里有你不知道的，晚上就好好睡觉，梦里有你想要的。', '别着急，好好走，一切，都来得及。一切皆有定数，顺其自然就好。', '别着急，好好走，一切，都来得及。一切皆有定数，顺其自然就好。', '学会遗忘，善忘是一件好事。要乐观，要努力，要笑。你看，你一开心，天下就变得美妙了。', '如今，不惊不扰，各自安好，你有你的城堡，我有我的孤岛。', '和他相遇的瞬间，我的人生就改变了。所见所闻所感，目之所及全都开始有了颜色。全世界，都开始发光发亮', '想把这一年所有的浪漫，温柔和爱，都送给春天，迎接你，春天你好。'];

function good() {
    let strs = (newDay[getRandom(0, newDay.length - 1)]);
    let i = 0;
    while (i < strs.length) {
        var oc = strs.substring(0, i + 1);
        i = i + 1;
    }
    setTimeout(function () {
        reply.style.display = "block";
    }, 2000);
    setTimeout(function () {
        reply.style.display = "none";
        let div = document.createElement('div');
        div.innerHTML = "<div class='messages_content'>" + oc + "</div>"
            + "<div class='messages_action'>" + showtime() + "</div>";
        div.className = "messages_item";
        let ci = messages.length;
        messages.insertBefore(div, messages.children[ci - 1]);
        messages.scrollTop = (0, messages.scrollHeight);
        throttle_valve = 1;
    }, 6000)
}
let head_portrait = document.querySelector("#head_portraits");
let head_portrait_bai = document.querySelector(".head_portrait_bai");
let head_portrait_hei = document.querySelector(".head_portrait_hei");
var head_portrait_index = 0;
head_portrait.addEventListener("click", function () {
    if (head_portrait_index == 0) {
        head_portrait_index = 1;
        head_portrait_hei.style.display = "block";
        head_portrait_bai.style.display = "none";
    } else {
        head_portrait_index = 0;
        head_portrait_bai.style.display = "block";
        head_portrait_hei.style.display = "none";
    }
})

var lis = document.querySelectorAll('.modal_nav_item');
var items = document.querySelectorAll('.tab_pane');
for (var i = 0; i < lis.length; i++) {
    lis[i].setAttribute('index', i);
    lis[i].onclick = function () {
        for (let i = 0; i < lis.length; i++) {
            lis[i].children[0].className = '';
        }
        this.children[0].className = 'item_active';
        let index = this.getAttribute('index');
        for (let i = 0; i < items.length; i++) {
            items[i].style.display = 'none';
        }
        items[index].style.display = 'block';
    }
}
var modal_btn = document.querySelector(".modal_btn");
modal_btn.addEventListener("click", function () {
    head_portrait_index = 0;
    head_portrait_bai.style.display = "block";
    head_portrait_hei.style.display = "none";
})
var eye_protection = document.querySelector(".eye_protection");
var dark_mode = document.querySelector(".dark_mode");
var normal_mode = document.querySelector(".normal_mode");
var mode = 0;
eye_protection.addEventListener("click", function () {
    if (mode == 0) {
        mode = 1;
        normal_mode.href = "./css/护眼.css";
        toggle.checked = false;
        switch_on.style.display = "block";
        switch_off.style.display = "none";
        localStorage.setItem('bgcolor', JSON.stringify([{ bgcolor: "1" }]));
    } else {
        mode = 0;
        normal_mode.href = "./css/copychat.css";
        toggle.checked = false;
        switch_on.style.display = "block";
        switch_off.style.display = "none";
        localStorage.setItem('bgcolor', JSON.stringify([{ bgcolor: "2" }]));
    }
})
var toggle = document.querySelector("#toggle");
var switch_on = document.querySelector(".switch_on");
var switch_off = document.querySelector(".switch_off");
toggle.addEventListener("click", function () {
    if (toggle.checked) {
        switch_on.style.display = "none";
        switch_off.style.display = "block";
        normal_mode.href = "./css/深色.css";
        localStorage.setItem('bgcolor', JSON.stringify([{ bgcolor: "3" }]));
    } else {
        switch_on.style.display = "block";
        switch_off.style.display = "none";
        if (mode == 1) {
            normal_mode.href = "./css/护眼.css";
            localStorage.setItem('bgcolor', JSON.stringify([{ bgcolor: "1" }]));
        } else {
            normal_mode.href = "./css/copychat.css";
            localStorage.setItem('bgcolor', JSON.stringify([{ bgcolor: "2" }]));
        }
    }
})
window.addEventListener("load", function () {
    let hk = JSON.parse(localStorage.getItem('bgcolor'));
    if (hk != null) {
        // 获取本地储存的默认背景色
        let i = hk[0].bgcolor;
        if (i == 1) {
            mode = 1;
            normal_mode.href = "./css/护眼.css";
        } else if (i == 2) {
            normal_mode.href = "./css/copychat.css";
        } else {
            toggle.checked = true;
            switch_on.style.display = "none";
            switch_off.style.display = "block";
            normal_mode.href = "./css/深色.css"
        }
    } else {
        normal_mode.href = "./css/copychat.css";
    }
})